<?php
declare(strict_types=1);

namespace app\admin\service;

use app\AliOosFile;
use think\facade\Log;

class AliOosService
{
    /**
     * 上传阿里云
     * @param $pathArr
     */
    public static function uploadAliOos($pathArr)
    {
        // 存储图片/视频到阿里云
        if ($pathArr) {
            foreach ($pathArr as $url) {
                $AliOos = new AliOosFile();
                // 去除开头的 /
                $urls = substr($url, 1);
                // 拼接完整路径
                $path = $_SERVER['DOCUMENT_ROOT'] . $url;
                $result = true;
                if (file_exists($path)) {
                    $result = $AliOos->upload($path, $urls);
                } else {
                    Log::write('上传到阿里云-文件数据不存在'.json_encode($path), 'error');
                }

                if (!$result) {
                    Log::write('上传到阿里云-文件数据失败'.json_encode($result), 'error');
                    continue;
                }
            }
        }
    }
}